
clear all
use data/judgeyear.dta

foreach x in iac   {
gen `x'0 = `x'time == 0
foreach j in "1" "2" "3" "4" "5" "6" {
gen `x'after`j' = `x'time == `j'
gen `x'before`j' = `x'time == -`j' 
}
}

foreach y in numops numdisc numwords numwords_maj_m numtoc_maj_m poscites_m distcites_m negcites_m discusscites_m quotecites_m outstatecites_m {
gen log`y' = log(1+`y')

}

bysort judgefe: egen meaniac = mean(iac10) if !iac10coterm & iac10window
gen iac6window = iactime >= -6 & iactime <= 6 if (meaniac > 0 & meaniac < 1)

// IAC, numops, discretionary
preserve
quietly areg lognumops iacbefore* iacafter* iac6window if iac6window == 1 & !mandeither, absorb(judgefe) vce(cluster judgefe)
parmest, norestore level(90)
gen otime=.
foreach j in "1" "2" "3" "4" "5" "6"  {
replace otime = -`j' if parm== "iacbefore`j'"
replace otime = `j' if parm== "iacafter`j'"
}
replace otime = 0 if strpos(parm, "o.")
drop if missing(otime)
sort otime
twoway line estimate otime || rline min90 max90 otime, lp(dash) ||, xline(0, lcolor(black) lwidth(vthin)) yline(0, lcolor(gray) lwidth(vthin)) xtitle(Years Before and After Establishment of IAC) legend(off) ytitle(Log Majority Opinions Written) ylabel(-.75(.25).75) xlabel(-6(3)6)
graph save figures/iac-numops-disc.gph, replace
graph export figures/iac-numops-disc.png, replace
restore

// IAC, numops, limited
preserve
quietly areg lognumops iacbefore* iacafter* iac6window if iac6window == 1 & mandeither, absorb(judgefe) vce(cluster judgefe)
parmest, norestore level(90)
gen otime=.
foreach j in "1" "2" "3" "4" "5" "6"  {
replace otime = -`j' if parm== "iacbefore`j'"
replace otime = `j' if parm== "iacafter`j'"
}
replace otime = 0 if strpos(parm, "o.")
drop if missing(otime)
sort otime
twoway line estimate otime || rline min90 max90 otime, lp(dash) ||, xline(0, lcolor(black) lwidth(vthin)) yline(0, lcolor(gray) lwidth(vthin)) xtitle(Years Before and After Establishment of IAC) legend(off) ytitle(Log Majority Opinions Written) ylabel(-.75(.25).75) xlabel(-6(3)6)
graph save figures/iac-numops-mand.gph, replace
graph export figures/iac-numops-mand.png, replace
restore

// IAC, numtoc, discretionary
preserve
quietly areg lognumtoc_maj_m iacbefore* iacafter* iac6window if iac6window == 1 & !mandeither, absorb(judgefe) vce(cluster judgefe)
parmest, norestore level(90)
gen otime=.
foreach j in "1" "2" "3" "4" "5" "6"  {
replace otime = -`j' if parm== "iacbefore`j'"
replace otime = `j' if parm== "iacafter`j'"
}
replace otime = 0 if strpos(parm, "o.")
drop if missing(otime)
sort otime
twoway line estimate otime || rline min90 max90 otime, lp(dash) ||, xline(0, lcolor(black) lwidth(vthin)) yline(0, lcolor(gray) lwidth(vthin)) xtitle(Years Before and After Establishment of IAC) legend(off) ytitle(Log Table of Cases Length) ylabel(-.3(.1).3) xlabel(-6(3)6)
graph save figures/iac-numtoc-disc.gph, replace
graph export figures/iac-numtoc-disc.png, replace
restore

// IAC, numtoc limited
preserve
quietly areg lognumtoc_maj_m iacbefore* iacafter* iac6window if iac6window == 1 & mandeither, absorb(judgefe) vce(cluster judgefe)
parmest, norestore level(90)
gen otime=.
foreach j in "1" "2" "3" "4" "5" "6"  {
replace otime = -`j' if parm== "iacbefore`j'"
replace otime = `j' if parm== "iacafter`j'"
}
replace otime = 0 if strpos(parm, "o.")
drop if missing(otime)
sort otime
twoway line estimate otime || rline min90 max90 otime, lp(dash) ||, xline(0, lcolor(black) lwidth(vthin)) yline(0, lcolor(gray) lwidth(vthin)) xtitle(Years Before and After Establishment of IAC) legend(off) ytitle(Log Table of Cases Length) ylabel(-.3(.1).3) xlabel(-6(3)6)
graph save figures/iac-numtoc-mand.gph, replace
graph export figures/iac-numtoc-mand.png, replace
restore

// IAC, poscites, discretionary
preserve
quietly areg logposcites_m iacbefore* iacafter* iac6window if iac6window == 1 & !mandeither, absorb(judgefe) vce(cluster judgefe)
parmest, norestore level(90)
gen otime=.
foreach j in "1" "2" "3" "4" "5" "6"  {
replace otime = -`j' if parm== "iacbefore`j'"
replace otime = `j' if parm== "iacafter`j'"
}
replace otime = 0 if strpos(parm, "o.")
drop if missing(otime)
sort otime
twoway line estimate otime || rline min90 max90 otime, lp(dash) ||, xline(0, lcolor(black) lwidth(vthin)) yline(0, lcolor(gray) lwidth(vthin)) xtitle(Years Before and After Establishment of IAC) legend(off) ytitle(Log Positive Cites Per Opinion) ylabel(-.3(.1).3) xlabel(-6(3)6)
graph save figures/iac-poscites-disc.gph, replace
graph export figures/iac-poscites-disc.png, replace
restore

// IAC, poscites limited
preserve
quietly areg logposcites_m iacbefore* iacafter* iac6window if iac6window == 1 & mandeither, absorb(judgefe) vce(cluster judgefe)
parmest, norestore level(90)
gen otime=.
foreach j in "1" "2" "3" "4" "5" "6"  {
replace otime = -`j' if parm== "iacbefore`j'"
replace otime = `j' if parm== "iacafter`j'"
}
replace otime = 0 if strpos(parm, "o.")
drop if missing(otime)
sort otime
twoway line estimate otime || rline min90 max90 otime, lp(dash) ||, xline(0, lcolor(black) lwidth(vthin)) yline(0, lcolor(gray) lwidth(vthin)) xtitle(Years Before and After Establishment of IAC) legend(off) ytitle(Log Positive Cites Per Opinion) ylabel(-.3(.1).3) xlabel(-6(3)6)
graph save figures/iac-poscites-mand.gph, replace
graph export figures/iac-poscites-mand.png, replace
restore

// IAC, discusscites_m, discretionary
preserve
quietly areg logdiscusscites_m iacbefore* iacafter* iac6window if iac6window == 1 & !mandeither, absorb(judgefe) vce(cluster judgefe)
parmest, norestore level(90)
gen otime=.
foreach j in "1" "2" "3" "4" "5" "6"  {
replace otime = -`j' if parm== "iacbefore`j'"
replace otime = `j' if parm== "iacafter`j'"
}
replace otime = 0 if strpos(parm, "o.")
drop if missing(otime)
sort otime
twoway line estimate otime || rline min90 max90 otime, lp(dash) ||, xline(0, lcolor(black) lwidth(vthin)) yline(0, lcolor(gray) lwidth(vthin)) xtitle(Years Before and After Establishment of IAC) legend(off) ytitle(Log Discussion Cites Per Opinion) ylabel(-.3(.1).3) xlabel(-6(3)6)
graph save figures/iac-discuscites-disc.gph, replace
graph export figures/iac-discuscites-disc.png, replace
restore

// IAC, poscites limited
preserve
quietly areg logdiscusscites_m  iacbefore* iacafter* iac6window if iac6window == 1 & mandeither, absorb(judgefe) vce(cluster judgefe)
parmest, norestore level(90)
gen otime=.
foreach j in "1" "2" "3" "4" "5" "6"  {
replace otime = -`j' if parm== "iacbefore`j'"
replace otime = `j' if parm== "iacafter`j'"
}
replace otime = 0 if strpos(parm, "o.")
drop if missing(otime)
sort otime
twoway line estimate otime || rline min90 max90 otime, lp(dash) ||, xline(0, lcolor(black) lwidth(vthin)) yline(0, lcolor(gray) lwidth(vthin)) xtitle(Years Before and After Establishment of IAC) legend(off) ytitle(Log Discussion Cites Per Opinion) ylabel(-.3(.1).3) xlabel(-6(3)6)
graph save figures/iac-discuscites-mand.gph, replace
graph export figures/iac-discuscites-mand.png, replace
restore